<?php

namespace App\Http\Controllers\System;

use App\Models\Permission;
use App\Package\Tree\Tree;
use App\Http\Controllers\Controller;
use App\Http\Requests\System\Permission\QueryCollection;

/**
 * 权限管理控制器
 *
 * Date: 22/03/2018
 * @author George
 * @package App\Http\Controllers\System
 */
class PermissionController extends Controller
{
	/**
	 * 获取权限树
	 *
	 * Date: 22/03/2018
	 * @author George
	 * @param QueryCollection $request
	 * @param Tree $generator
	 * @return \Illuminate\Http\JsonResponse
	 * @throws \App\Exceptions\GeneralException
	 */
	public function index(QueryCollection $request, Tree $generator)
	{
		$permissions = Permission::query()->select(['code', 'parent_code', 'name'])->get();
		$tree = $generator->make($permissions, 'code', 'parent_code', 'children', 'top');
		return success($tree);
	}
}
